import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'
import type { CoreTree } from '/@/tool/CoreTree'

import orgService from '/@/api/cn/core/sign/orgService'

import type { Org } from '/@/model/cn/core/sign/eo/Org'
import type { OrgQO } from '/@/model/cn/core/sign/qo/OrgQO'
import type { OrgVO } from '/@/model/cn/core/sign/vo/OrgVO'

interface OrgState {
}

export const useOrgStore = defineStore({
  id: 'org',
  state: (): OrgState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<Org>): Promise<Res<Org>> {
      return new Promise<Res<Org>>((resolve, reject) => {
        orgService.save(param).then((res: AxiosResponse<Res<Org>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<Org>): Promise<Res<Org>> {
      return new Promise<Res<Org>>((resolve, reject) => {
        orgService.saveBatch(param).then((res: AxiosResponse<Res<Org>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<Org>): Promise<Res<Org>> {
      return new Promise<Res<Org>>((resolve, reject) => {
        orgService.update(param).then((res: AxiosResponse<Res<Org>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<Org>): Promise<Res<Org>> {
      return new Promise<Res<Org>>((resolve, reject) => {
        orgService.updateBatch(param).then((res: AxiosResponse<Res<Org>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<Org>): Promise<Res<Org>> {
      return new Promise<Res<Org>>((resolve, reject) => {
        orgService.remove(param).then((res: AxiosResponse<Res<Org>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<Org>): Promise<Res<Org>> {
      return new Promise<Res<Org>>((resolve, reject) => {
        orgService.removeBatch(param).then((res: AxiosResponse<Res<Org>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<OrgQO>): Promise<Res<Org>> {
      return new Promise<Res<Org>>((resolve, reject) => {
        orgService.count(param).then((res: AxiosResponse<Res<Org>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<OrgQO>): Promise<Res<Org>> {
      return new Promise<Res<Org>>((resolve, reject) => {
        orgService.pk(param).then((res: AxiosResponse<Res<Org>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<OrgQO>): Promise<Res<Org>> {
      return new Promise<Res<Org>>((resolve, reject) => {
        orgService.query(param).then((res: AxiosResponse<Res<Org>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<OrgQO>): Promise<Res<Org>> {
      return new Promise<Res<Org>>((resolve, reject) => {
        orgService.paging(param).then((res: AxiosResponse<Res<Org>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<OrgQO>): Promise<Res<OrgVO>> {
      return new Promise<Res<OrgVO>>((resolve, reject) => {
        orgService.countVo(param).then((res: AxiosResponse<Res<OrgVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<OrgQO>): Promise<Res<OrgVO>> {
      return new Promise<Res<OrgVO>>((resolve, reject) => {
        orgService.pkVo(param).then((res: AxiosResponse<Res<OrgVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<OrgQO>): Promise<Res<OrgVO>> {
      return new Promise<Res<OrgVO>>((resolve, reject) => {
        orgService.queryVo(param).then((res: AxiosResponse<Res<OrgVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<OrgQO>): Promise<Res<OrgVO>> {
      return new Promise<Res<OrgVO>>((resolve, reject) => {
        orgService.pagingVo(param).then((res: AxiosResponse<Res<OrgVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    getOrgTreeData(param: Param<OrgQO>): Promise<Res<CoreTree<any>>> {
      return new Promise<Res<CoreTree<any>>>((resolve, reject) => {
        orgService.getOrgTreeData(param).then((res: AxiosResponse<Res<CoreTree<any>>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    getOrgPostTreeData(param: Param<OrgQO>): Promise<Res<CoreTree<any>>> {
      return new Promise<Res<CoreTree<any>>>((resolve, reject) => {
        orgService.getOrgPostTreeData(param).then((res: AxiosResponse<Res<CoreTree<any>>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    getOrgPostStaffTreeData(param: Param<OrgQO>): Promise<Res<CoreTree<any>>> {
      return new Promise<Res<CoreTree<any>>>((resolve, reject) => {
        orgService.getOrgPostStaffTreeData(param).then((res: AxiosResponse<Res<CoreTree<any>>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useOrgStoreWithout() {
  return useOrgStore(store)
}
